home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / PowerPC / Dev / PPCRelease / Examples / IPC / Msg4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-07  |  4.5 KB  |  166 lines

  1. /* Msg4 and Msg4PPC.elf
  2.  * 
  3.  * This test program sends 1000 messages to the M68k and
  4.  * shows how long this takes.
  5.  * The Messages are send synchron and every msg must
  6.  * be replied after another.
  7.  * Each Message has the Body "Text sent by PPC processor\n"
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/nodes.h>
  12. #include <exec/lists.h>
  13. #include <exec/memory.h>
  14. #include <utility/tagitem.h>
  15. #include <powerup/ppclib/interface.h>
  16. #include <powerup/ppclib/message.h>
  17. #include <powerup/ppclib/tasks.h>
  18. #include <powerup/proto/ppc.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include "time.h"
  24. #include "time_protos.h"
  25.  
  26. #define    MSGCOUNT    1000
  27.  
  28. struct StartupData
  29. {
  30.     void    *MsgPort;
  31.     ULONG    MsgCount;
  32. };
  33.  
  34. extern struct Library    *SysBase;
  35.  
  36. int    main(void)
  37. {
  38. struct Library        *PPCLibBase;
  39. struct TagItem        MyTags[10];
  40. void            *M68kPort;
  41. void            *StartupMsg;
  42. void            *PPCMsg;
  43. void            *ElfObject;
  44. void            *Task;
  45. struct StartupData    *StartupData;
  46. void            *MyTimerObject;
  47. ULONG            i;
  48.  
  49.   Printf("Opening ppc.library\n");
  50.   if (PPCLibBase = OpenLibrary("ppc.library", 44))
  51.   {
  52.     if (MyTimerObject=TimerCreateObject())
  53.     {
  54.       Printf("Loading PPC object\n");
  55.       if (ElfObject=PPCLoadObject("PROGDIR:Msg4PPC.elf"))
  56.       {
  57.         MyTags[0].ti_Tag    =    TAG_DONE;
  58.         if (M68kPort = PPCCreatePort(MyTags))
  59.         {
  60.           if (StartupMsg = PPCCreateMessage(M68kPort, 0))
  61.           {
  62.             Printf("Allocating StartupData\n");
  63.             if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
  64.             {
  65.               StartupData->MsgPort    =    M68kPort;
  66.               StartupData->MsgCount    =    MSGCOUNT;
  67.  
  68.               Printf("Creating PPC task\n");
  69.               MyTags[0].ti_Tag        =    PPCTASKTAG_STARTUP_MSG;
  70.               MyTags[0].ti_Data        =(ULONG) StartupMsg;
  71.  
  72.               MyTags[1].ti_Tag        =    PPCTASKTAG_STARTUP_MSGDATA;
  73.               MyTags[1].ti_Data    =(ULONG) StartupData;
  74.  
  75.               MyTags[2].ti_Tag        =    PPCTASKTAG_STARTUP_MSGLENGTH;
  76.               MyTags[2].ti_Data        =    0;
  77.  
  78.               MyTags[3].ti_Tag        =    PPCTASKTAG_STARTUP_MSGID;
  79.               MyTags[3].ti_Data        =    0;
  80.  
  81.               MyTags[4].ti_Tag        =    PPCTASKTAG_MSGPORT;
  82.               MyTags[4].ti_Data        =    TRUE;
  83.  
  84.               MyTags[5].ti_Tag        =    TAG_DONE;
  85.  
  86.               if (Task = PPCCreateTask(ElfObject, MyTags))
  87.               {
  88.                 Printf("Receiving SYNCHRON messages with a *Body* and wait for each reply...");
  89.  
  90.                 TimerSetAttr(MyTimerObject,TIMERTAG_START);
  91.  
  92.                 i = 0;
  93.  
  94.                 while(i<MSGCOUNT)
  95.                 {
  96.                  PPCWaitPort(M68kPort);
  97.                  while (i<MSGCOUNT && (PPCMsg=PPCGetMessage(M68kPort)))
  98.                  {
  99.                    PPCReplyMessage(PPCMsg);
  100.                    i++;
  101.                  }
  102.                 }
  103.                 TimerSetAttr(MyTimerObject,TIMERTAG_STOP);
  104.                 TimerShow(MyTimerObject);
  105.  
  106.                 Printf("Received and replied %ld SYNCHRON messages...\n",i);
  107.  
  108.                 Printf("Waiting for Task Finish Msg...\n");
  109.                 for (;;)
  110.                 {
  111.                   if ((PPCMsg=PPCGetMessage(M68kPort)) == StartupMsg)
  112.                   {
  113.                     Printf("Ahh..the expected Startup=Finish Msg was received.\nNow we can savely free all resources.\n");
  114.                     break;
  115.                   }
  116.                   else
  117.                   {
  118.                     Printf("Some non replied Msg 0x%lx was found..wait\n",
  119.                            PPCMsg);
  120.                     PPCWaitPort(M68kPort);
  121.                   }
  122.                 }
  123.               }
  124.               else
  125.               {
  126.                 Printf("Could not create PPC task\n");
  127.               }
  128.               PPCFreeVec(StartupData);
  129.             }
  130.             else
  131.             {
  132.               Printf("Could not alloc Startup Data\n");
  133.             }
  134.             PPCDeleteMessage(StartupMsg);
  135.           }
  136.           else
  137.           {
  138.             Printf("Could not create Startup message\n");
  139.           }
  140.           Printf("Deleting message port...");
  141.           while (PPCDeletePort(M68kPort) == FALSE);
  142.         }
  143.         else
  144.         {
  145.           Printf("Could not create M68k MsgPort\n");
  146.         }
  147.         Printf("Unloading PPC object\n");
  148.         PPCUnLoadObject(ElfObject);
  149.       }
  150.       else
  151.       {
  152.         Printf("Could not load the elfobject\n");
  153.       }
  154.       TimerDeleteObject(MyTimerObject);
  155.     }
  156.     Printf("Closing ppc.library\n");
  157.     CloseLibrary(PPCLibBase);
  158.   }
  159.   else
  160.   {
  161.     Printf("Could not open ppc.library v44+\n");
  162.   }
  163.   return(0);
  164. }
  165.  
  166.